package com.os;

import java.util.ArrayList;
import mapgenerator.Main;

/**
 * @version 1.0
 * @author Sajarwo Anggai
 */
public class ObjectSpriteContainer {

    private ArrayList sprites;
    private ArrayList spritesMapping;
    private Main comp;

    public ObjectSpriteContainer(Main comp) {
        this.comp = comp;
        sprites = new ArrayList();
        spritesMapping = new ArrayList();
    }

    public void clearAll() {
        sprites.clear();
        spritesMapping.clear();
    }

    /**
     * Mengambil list object sprite
     * @return ArrayList yang berisi list sprite
     */
    public ArrayList getSprites() {
        return sprites;
    }

    /**
     * Manambahkan object sprite kedalam container dan akan mengirimkan pesan
     * warning apabila nama sprite sudah ditambahkan atau sudah ada didalam container.
     * @param os ObjectSprite akan disimpan kedalam container
     * @return false apabila gagal atau terjadi diplikasi nama object sprite.
     */
    public boolean addSprites(ObjectSprite os) {
        if (!spritesMapping.contains(os.getName())) {
            sprites.add(os);
            spritesMapping.add(os.getName());
            return true;
        } else {
            System.out.println("Sprite Name has been added try other name!");
            return false;
        }
    }

    /**
     * Mengahapus ObjectSprite yang ada didalam container
     * @param os ObjectSprite yang akan dihapus
     * @return true apabila berhasil dihapus
     */
    public boolean removeSprites(ObjectSprite os) {
        spritesMapping.remove(os.getName());
        return sprites.remove(os);
    }

    /**
     * Merename object sprite
     * @param name nama pengganti
     * @return true apabila sprite dapat di rename
     */
    public boolean renameSprites(ObjectSprite os, String osName) {
        if (!spritesMapping.contains(osName)) {
            spritesMapping.set(spritesMapping.indexOf(os.getName()), osName);
            os.setName(osName);
            return true;
        } else {
            return false;
        }
    }
}
